﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;
using WhatCatch.Core2.Model;

namespace WhatCatch.Core2
{
    public class CatchQueue : ICatchQueue
    {
        static object lockQueue = new object();
        ConcurrentQueue<CatchTask> _queueTask = new ConcurrentQueue<CatchTask>();
        static object lockResult = new object();
        ConcurrentQueue<CatchResult> _queueResult = new ConcurrentQueue<CatchResult>();

        public CatchTask TaskDequeue()
        {
            CatchTask task;
            lock (lockQueue)
            {
                if (_queueTask.TryDequeue(out task) == false)
                {
                    return null;
                }
            }
            return task;
        }

        public bool TaskEnqueue(CatchTask task)
        {
            lock (lockQueue)
            {
                _queueTask.Enqueue(task);
            }
            return true;
        }

        public CatchResult ResultDequeue()
        {
            CatchResult result;
            lock (lockQueue)
            {
                if (_queueResult.TryDequeue(out result) == false)
                {
                    return null;
                }
            }
            return result;
        }

        public bool ResultEnqueue(CatchResult result)
        {
            lock (lockQueue)
            {
                _queueResult.Enqueue(result);
            }
            return true;
        }

        
    }
}
